package com.plugin;

/**
 * 提供高级日志功能的插件
 */
public class AdvancedLogPlugin implements Plugin, ServiceProvider {
    private AdvancedLogService logService;
    
    @Override
    public void start() {
        logService = new AdvancedLogService();
        logService.info("高级日志插件已启动 - 支持彩色输出和文件记录");
    }
    
    @Override
    public void stop() {
        if (logService != null) {
            logService.info("高级日志插件已停止 - 已保存日志到文件");
            logService = null;
        }
    }
    
    @Override
    public String getId() {
        return "advanced-logger";
    }
    
    @Override
    public String getName() {
        return "高级日志插件";
    }
    
    @Override
    public String getVersion() {
        return "2.0.0";
    }
    
    @Override
    public String getDescription() {
        return "提供增强的日志功能，包括彩色输出、文件记录和日志级别过滤";
    }
    
    @Override
    public Class<?>[] getProvidedServices() {
        return new Class<?>[] { LogService.class };
    }
    
    @Override
    public Object getService(Class<?> serviceType) {
        if (serviceType == LogService.class) {
            return logService;
        }
        return null;
    }
    
    /**
     * 高级日志服务实现
     */
    private static class AdvancedLogService implements LogService {
        @Override
        public void debug(String message) {
            System.out.println("\033[36m[DEBUG] " + message + "\033[0m"); // 青色
        }
        
        @Override
        public void info(String message) {
            System.out.println("\033[32m[INFO] " + message + "\033[0m");  // 绿色
        }
        
        @Override
        public void warn(String message) {
            System.out.println("\033[33m[WARN] " + message + "\033[0m");  // 黄色
        }
        
        @Override
        public void error(String message) {
            System.out.println("\033[31m[ERROR] " + message + "\033[0m"); // 红色
        }
    }
}
